package cn.hk.dept.controller;


import cn.hk.common.entity.Result;
import cn.hk.dept.domain.Area;
import cn.hk.dept.domain.vo.DeptInfoVo;
import cn.hk.dept.domain.vo.DeptVo;
import cn.hk.dept.service.DeptService;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 部门表 前端控制器
 * </p>
 *
 * @author xu
 * @since 2023-03-09
 */
@Api("社区服务")
@RestController
@RequestMapping("/deptservice/dept")
public class DeptController {

    @Autowired
    private DeptService deptService;


    /**
     * 查找社区集合
     * @return
     */
    @ApiOperation("社区选择")
    @GetMapping("/deptSelectedList")
    public Result deptSelectedList(){
        List<Area> areaTrees = deptService.getAreaList();
        JSONArray areaTreesJsonArrayon = JSONUtil.parseArray(areaTrees);
        return Result.success().put("item",areaTreesJsonArrayon);
    }

    /**
     * 查找社区科室ByAreaCode
     * @param areaCode
     * @return
     */
    @GetMapping("/getDeptListByAreaCode/{areaCode}")
    public Result getDeptListByAreaCode(@PathVariable String areaCode){
        List<DeptVo> deptVoList = deptService.getListByAreaCode(areaCode);
        return Result.success().put("item", deptVoList);
    }

    /**
     * 查找社区科室
     * @param deptId
     * @return
     */
    @GetMapping("/getDept/{deptId}")
    public Result getDeptName(@PathVariable Long deptId){
        List<DeptInfoVo> deptInfoVoList = deptService.getDeptByPId(deptId);
        return Result.success().put("item", deptInfoVoList);
    }
}

